import re

from google.appengine.ext import ndb


class UnnaturalName(ndb.Model):
    name = ndb.StringProperty()
    natural_name = ndb.ComputedProperty(
        lambda self: self.natural_name_generator(self.name))

    def natural_name_generator(self, name):
        chunks = re.findall("(\d+|[A-Za-z]+)", name)
        sub_word_list = [re.match('\d', x) and x.zfill(6) or x.lower() for x in chunks]

        normalized_string = '-'.join(str(chunk) for chunk in sub_word_list)

        return normalized_string

    @property
    def normalized_name(self):
        chunks = re.findall("(\d+|[A-Za-z]+)", self.name)
        sub_word_list = [re.match('\d', x) and int(x) or x for x in chunks]

        return sub_word_list
